package com.shujia.flink.tf

import org.apache.flink.api.common.functions.FilterFunction
import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}

object Demo3Filter {
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment



    val studentDS: DataStream[String] = env.readTextFile("data/students.txt")


    val filterDS: DataStream[String] = studentDS.filter(new FilterFunction[String] {
      /**
        *
        *
        * @param value ： 数据
        * @return ： 返回值，如果返回true 保留数据，如果返回false 过滤数据
        */
      override def filter(value: String): Boolean = {

        val gender: String = value.split(",")(3)

        "男".equals(gender)
      }
    })

    filterDS.print()

    env.execute()


  }

}
